package cn.webrx;

import java.io.FileOutputStream;
import java.io.IOException;

public class TryWithCatch {
    public static void main(String[] args) {


        //jdk 1.7 trywithresources语句
        try (FileOutputStream fos = new FileOutputStream("us.txt")) {
            fos.write("hello 要工要械".getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }


        //jdk 1.7 以前
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("user.txt");
            fos.write("hello 中文".getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
